package com.waghost.bridalgown.aop;

import com.waghost.bridalgown.annotaion.Logging;
import com.waghost.bridalgown.dao.LogsDao;
import com.waghost.bridalgown.entity.Logs;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
// AOP切面Logging日志
@Aspect
@Component
public class LoggingAop {
    @Autowired
    private LogsDao logsDao;
    @Before("@annotation(com.waghost.bridalgown.annotaion.Logging)")
    public void logMethod(JoinPoint joinPoint) {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Logging loggingAnnotation = signature.getMethod().getAnnotation(Logging.class);

        if (loggingAnnotation != null) {
            Integer uuid = loggingAnnotation.uuid();
            Integer type = loggingAnnotation.type();

            // 在这里处理 uuid 和 type 值
            Logs logs = new Logs();
            logs.setCreateTime(new Date());
            logs.setType(type);
            logs.setUuid(uuid);
            logsDao.insert(logs);
        }
    }
}
